<template>
	<view style="padding-top: 90rpx;">
		<scroll-view scroll-x class="bg-white nav text-center fixed">
			<view class="cu-item" :class="index==tabIndex?'text-red cur':''" v-for="(item,index) in tabList"
				:key="index" @tap="tabSelect" :data-id="index">
				{{item.text}}
			</view>
		</scroll-view>
		<view v-if="dataObj.length === 0">
			<view class="padding-lr padding-bottom" style="margin-top: 10%;">
				<view class="padding-xs flex align-center">
					<view class="flex-sub text-center">
						<view class="solid-bottom text-xsl padding">
							<text class="cuIcon-warnfill text-gray"></text>
						</view>
						<view class="padding">暂无数据</view>
					</view>
				</view>
			</view>
		</view>
		<scroll-view v-else scroll-y class="page show">
			<view class="cu-list menu-avatar">
				<view class="cu-item" v-for="(item,index) in dataObj" :key="index">
					<view class="cu-avatar round lg" :style="'background-image:url('+item.avatar+'?thumb=1);'" />
					<view class="content">
						<view class="text-grey text-lg">{{item.name}}</view>
						<view class="text-gray flex" v-if="item.graduationYear">
							<view class="text-cut">
								{{item.graduationYear}}届{{item.graduationClass}}
							</view>
						</view>
					</view>
					<view class="">
						{{item.phone}}
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		card_same
	} from '@/common/api/api.js'

	export default {
		data() {
			return {
				cardInfo: uni.getStorageSync("cardInfo"),
				tabIndex: 0,
				tabList: [],
				dataObj: [],
				params: {},

			};
		},
		onLoad(e) {
			if (e._t) {
				this.tabIndex = e._t
			}
			this.tabList = []
			this.cardInfo.studentList.forEach(item => {
				this.tabList.push({
					code: item.position,
					text: item.position + item.graduationYear + '(' + item.graduationClass + ')'
				})
			});
			this.tabList.push({
				code: "SameCity",
				text: "同城校友"
			})
			this.params.position = this.tabList[this.tabIndex].code
			this.getData()
		},
		methods: {
			getData() {
				this.loadStatus = 'loading'
				card_same(this.params).then(res => {
					let records = this.$s.res(res)
					if (records && records.length > 0) {
						this.dataObj = records
					}
				}).catch(err => {
					this.loadStatus = 'loadmore'
				});
			},
			tabSelect(e) {
				this.dataObj = []
				this.tabIndex = e.currentTarget.dataset.id;
				this.params.position = this.tabList[this.tabIndex].code
				this.getData()
			}
		}
	}
</script>

<style>
	.page {
		height: 100Vh;
		width: 100vw;
	}

	.page.show {
		overflow: hidden;
	}

	.switch-sex::after {
		content: "\e716";
	}

	.switch-sex::before {
		content: "\e7a9";
	}

	.switch-music::after {
		content: "\e66a";
	}

	.switch-music::before {
		content: "\e6db";
	}
</style>